package com.coldchain.admin.rpc;

import com.coldchain.admin.config.service.IAreaService;
import com.coldchain.admin.config.service.ICarTypeService;
import com.coldchain.admin.config.service.ISystemService;
import com.coldchain.admin.resoure.service.IMenuService;
import com.coldchain.authclient.annotation.CheckUserToken;
import com.coldchain.common.enums.EnableStatusEnums;
import com.coldchain.common.msg.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName SystemRpcController
 * @Description TODO
 * @Author fangliai
 * @Date 2018/9/22 13:09
 * @Vesion 1
**/
@RestController
public class SystemRpcController {


    @Autowired
    private IAreaService cityService;

    @Autowired
    private ICarTypeService carTypeService;

    @Autowired
    private ISystemService systemService;

    @Autowired
    private IMenuService menuService;



    /**
     * 获取开放的城市
     * @return
     */
    @GetMapping("/city/openList")
    public Object getOpenCityList(){
        try{

            Map<String,Object> params=new HashMap<>();
            params.put("level",2);
            params.put("enable", EnableStatusEnums.OPEN.getValue());
            return new ObjectRestResponse().data(cityService.selectCityVo(params)).succeed("ok");

        }catch (Exception e) {

            return new ObjectRestResponse().error("系统繁忙,请稍候重式");
        }
    }

    @GetMapping("/getCarTypeList")
    public  Object getCarTypeList(){
        try{

            return  new ObjectRestResponse<>().data( carTypeService.getAllCarType()).succeed("OK");

        }catch (Exception e) {

            return new ObjectRestResponse<>().error("系统繁忙,请稍候重式");
        }

    }


    @GetMapping("/getCarTypeInfo/{id}")
    public Object getCarTypeInfo(@PathVariable("id") Integer id){
        try{

            return new ObjectRestResponse<>().data(carTypeService.getCarTypeVoInfoById(id));

        }catch (Exception e) {

            return new ObjectRestResponse<>().error("系统繁忙,请稍候重式");
        }
    }


    @GetMapping("/getSystemInfo")
    public Object getSystemInfo(){
        try{

            return new ObjectRestResponse<>().data(systemService.getAppConfig());

        }catch (Exception e) {

            return new ObjectRestResponse<>().error("系统繁忙,请稍候重式");

        }
    }

    @GetMapping("/getCurrentUserMenu")
    @CheckUserToken
    public Object getCurrentUserMenu(){
        try{

            return new ObjectRestResponse<>().data(menuService.getCurrentUserMenu());

        }catch (Exception e) {

            return new ObjectRestResponse<>().error("系统繁忙,请稍候重式");

        }
    }

}
